#include "font.h"
#include "stdlib.h"
#include "codepages.h"
#include "font_builtin.h"

//-------------------------------------------------------------------
#define DEFAULT_SYMBOL          0xFFFD

//-------------------------------------------------------------------
unsigned char current_font[256][16];

//-------------------------------------------------------------------
static int font_find_data (int charcode) {
    int i=0;

    while (font_data[i].charcode != -1) {
        if (font_data[i].charcode == charcode) 
            return i;
        ++i;
    }
    return -1;
}

//-------------------------------------------------------------------
void font_init() {
//    font_init_data(cp_common, 0, 128);
//    font_init_data(codepages[FONT_CP_WIN_1251], 128, 128);
}

//-------------------------------------------------------------------
void font_set(int codepage) {
	int i,n;
	unsigned short charcode;
	char buf[4];

	buf[1] = 0;
	buf[2] = 0;
	buf[3] = 0;

	for(i=0; i<256; i++){
		buf[0] = i;
		charcode = font_cp[codepage]->getc(buf, &n);
		n = font_find_data(charcode);
		if(n == -1){
            n = font_find_data(DEFAULT_SYMBOL);
        }
        memcpy(current_font[i], font_data[n].data, 16);
	}
}

//-------------------------------------------------------------------
